package com.minelx.autocha;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class WebBrowser implements IWebBrowser {
	private final ChromeDriver driver;

	WebBrowser(ChromeOptions options) {
		driver = new ChromeDriver(options);
	}

	@Override
	public void open(String url) {
		driver.get(url);
	}

	@Override
	public WebNode id(String name) {
		return new WebNode(driver, IElementLocation.id(name));
	}

	@Override
	public WebNode selector(String selector) {
		return new WebNode(driver, IElementLocation.selector(selector));
	}

	@Override
	public ChromeDriver coreDriver() {
		return driver;
	}

	@Override
	public void close(long after) {
		WebNode.sleep(after);
		driver.quit();
	}

	@Override
	public void close() {
		driver.quit();
	}
}
